{extend name="wap/default/base" /}
{block name="resources"}
    <style type="text/css">
		#main{margin-top: 45px;padding-top: 3px;}
		#main p{padding: 5px;}
		.prompt{
		    margin: 5px auto;
		    background-color: #fff2c0;
		    color: #d8af12;
		}
/* 		.content{text-align: center;} */
		.content .text{
			margin:0px 8px;
/* 			border-bottom: 1px solid #eee; */
		}
		.content input{height: 30px;width: 74%;border:1px solid #ddd;padding-left: 0px;}
		.content .buttom input[type='button']{
		    display: block;
		    width: 90%;
		    margin: auto;
		    background-color: #f03737;
		    color: #fff;
		    height: 32px;
		    line-height: 32px;
		    border-radius: 6px;
		}
		.circle{
	    width: 60px;
	    height: 60px;
	    border-radius: 50%;
	    border: 1px solid #F03737;
	    text-align: center;
/* 	    line-height: 30px; */
	    margin: 0 auto;
	    padding:5px;
		}
	</style>
{/block}
{block name="goodsHead"}
<section class="head">
		<a class="head_back" onclick="window.history.go(-1)" href="javascript:void(0)"><i class="icon-back"></i></a>
		<div class="head-title">积分兑换余额</div>
	</section>
{/block}
{block name="main"}
	 <div id="main" >
	 	<p class="prompt">* 兑换比例为1积分兑换{$accounts}元</p>
	 	<div style="margin-top: 16px;">
	 		<div class="circle">
		 		<span style="color:#F03737;">积分</span><br/>
		 		<span style="color:#F03737;font-size:25px;">{$conponSum}</span>
		 	</div>
	 		
	 	</div>
	 	<div class="content">
	 		<p class="text" style="margin-top: 15px;margin-bottom: 7px;"><span>兑换积分:</span><input type="text" max="100" min="0" id="amount" name="amount" placeholder="请输入积分数量" style="margin: 0 5px;padding-left: 3px;"/></p>
	 		<p style="width: 74%;float: right;color: #d8af12;margin-top: -11px;margin-bottom: 20px;">最多可兑换{$conponSum}积分</p>
	 		<p class="buttom"><input type="button" id="duih" value="兑换"/></p>
	 	</div>
	 </div>
	 
	 <script type="text/javascript">
	 	var conponSum='{$conponSum}';
	 	var shopid='{$shop_id}';
		$(function(){
			$('.content>p.buttom>#duih').click(function(){
				$(this).attr('disabled','disabled');
				var flag=true;
				var msg="";
				var amount=$('#amount');
				if(amount.val()==''){
					msg="需要兑换的积分不可为空";
					flag=false;
				}else if(Number(amount.val())>Number(conponSum)){
					msg="需要兑换的积分不可大于所拥有的积分";
					amount.val(conponSum);
					flag=false;
				}else if(Number(amount.val())<0){
					msg="需要兑换的积分不可小于0";
					amount.val(0);
					flag=false;
				}
				
				if(!flag){
					layer.msg(msg);
					amount.focus();
					$(this).removeAttr('disabled');
					return false;
				}
				
				 $.post("{:__URL('APP_MAIN/member/ajaxintegralexchangebalance')}",{'amount':amount.val(),'shop_id':shopid},
						  function(data){
						    if(data['code']>0){
						    	layer.msg('积分兑换成功');
						    	 setTimeout(function(){
						    		 location.href="{:__URL('APP_MAIN/member/integralwater?shop_id='.$shop_id)}"
						            },1000);
						    }else{
						    	$(this).removeAttr('disabled');
						    	layer.msg(data['message']);
						    }
						  },
				  "json");//这里返回的类型有：json,html,xml,text
			})
		})
	</script>
{/block}
{block name="bottom"}
{/block}